/* --------------------------Usercode Section------------------------ */
package compilador;
import java_cup.runtime.*;
      
%%
   
/* -----------------Options and Declarations Section----------------- */
   
%class Scanner
%line
%column
%cup
   

%{   
    private Symbol symbol(int type) {
        return new Symbol(type, yyline, yycolumn);
    }
    
    private Symbol symbol(int type, Object value) {
        return new Symbol(type, yyline, yycolumn, value);
    }
%}
   

/*
  Macro Declarations
  
  These declarations are regular expressions that will be used latter
  in the Lexical Rules Section.  
*/

letter          = [A-Za-z]
digit           = [0-9]
alphanumeric    = {letter}|{digit}
other_id_char   = [_]
identifier      = {letter}({alphanumeric}|{other_id_char})*
integer         = {digit}*
real            = {integer}\.{integer}
char            = '.'
leftbrace       = \/\/
rightbrace      = \]
nonrightbrace   = [^}]
comment_body    = {nonrightbrace}*
comment         = {leftbrace}{comment_body}
whitespace      = [ \n\t]
%%
/* ------------------------Lexical Rules Section---------------------- */

programa		{ return symbol(sym.programa); }  
classe 			{ return symbol(sym.classe);}
objeto 			{ return symbol(sym.objeto);}
novaInstancia	{ return symbol(sym.novaInst);}
escondido	{ return symbol(sym.escondido);}
visivel		{ return symbol(sym.visivel);}
esta		{ return symbol(sym.esta);}
atrb 		{ return symbol(sym.atributo);}
se 			{ return symbol(sym.se); }  
entao 		{ return symbol(sym.entao);}  
senao 		{ return symbol(sym.senao);}  
var			{ return symbol(sym.var);}
inteiro		{ return symbol(sym.inteiro);}
mostre		{ return symbol(sym.imprime);}
verdadeiro	{ return symbol(sym.verdadeiro);}
falso		{ return symbol(sym.falso);}		
retorne		{ return symbol(sym.retorne);}
Principal	{ return symbol(sym.inicioMain);}
	{ return symbol(sym.booli);}
".."	{ return symbol(sym.fimMain);}
":"		{ return symbol(sym.inicio);}  
"."		{ return symbol(sym.fim); }  
","		{ return symbol(sym.virg); }
">"		{ return symbol(sym.referenciador); }
"("		{ return symbol(sym.abreParenteses); }
")"		{ return symbol(sym.fechaParenteses); }
";"		{ return symbol(sym.ptvirg); }
"::"	{ return symbol(sym.doispt); }
"+"		{ return symbol(sym.soma); }
"-"		{ return symbol(sym.subt); }
"*"		{ return symbol(sym.mult); }
"/"		{ return symbol(sym.divi); }
"=="	{ return symbol(sym.igual); }
"="		{ return symbol(sym.atribuicao); }
"	" 	{ return symbol(sym.ident); }
{identifier}	{ return symbol(sym.identificador, new String(yytext()));}
{integer}		{ return symbol(sym.intnum, new Integer(yytext()));}
{real}			{ return symbol(sym.realnum, new Float(yytext()));}
{boolean}		{ return symbol(sym.booli, new Boolean(yytext()));}
{comment}       { /* For this stand-alone lexer, print out comments. */
                  System.out.println("Recognized comment: " + yytext()); }
{whitespace}    { /* Ignore whitespace. */ }
.|\n               {}// System.out.println("Illegal char, '" + yytext() + "' line: " + yyline + ", column: " + yychar); }